﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinkCard.Model;
namespace LinkCard.Dao
{
    public class LogDao
    {
        public int Add(object obj)
        {
            var rs = 0;
            try
            {
                var db = new TopLinkEntities();
                var objAdd = (Logs)obj;
                db.AddToLogs(objAdd);
                rs = db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return rs;
        }

        public Logs GetById(long id)
        {
            var ct = new Logs();
            try
            {
                var db = new TopLinkEntities();
                ct = db.Logs.FirstOrDefault(t => t.ID == id);
            }
            catch (Exception)
            {
                throw;
            }
            return ct;
        }

        public List<Logs> GetAll()
        {
            var lst = new List<Logs>();
            try
            {
                var db = new TopLinkEntities();
                lst = db.Logs.ToList();
            }
            catch (Exception)
            {
                throw;
            }
            return lst;
        }
        public List<Logs> GetAllByUser(Int64 iUserID)
        {
            var lst = new List<Logs>();
            try
            {
                var db = new TopLinkEntities();
                lst = db.Logs.Where(t => t.UserID == iUserID).ToList();
            }
            catch (Exception)
            {
                throw;
            }
            return lst;
        }
    }
}
